﻿using System.Windows.Input;
using IS_Ever_Green.DataAccess.Model;
using IS_Ever_Green.DataAccess.Model.Repositories;

namespace IS_Ever_Green.ViewModel
{
    public class AdminViewModel : BaseViewModel
    {
        private IUserRepository _userRepository;
        private UserModel _currentUser;
        private BaseViewModel _baseViewModel;
        private string _caption;
        private string _captionMain;

        public UserModel CurrentUser
        {
            get { return _currentUser; }
            set
            {
                _currentUser = value;
                OnPropertyChanged(nameof(CurrentUser));
            }
        }

        public BaseViewModel BaseViewModel
        {
            get { return _baseViewModel; }
            set { _baseViewModel = value; OnPropertyChanged(nameof(BaseViewModel)); }
        }

        public string Caption
        {
            get { return _caption; }
            set { _caption = value; OnPropertyChanged(nameof(Caption)); }
        }

        public string CaptionMain
        {
            get { return _captionMain; }
            set { _captionMain = value; OnPropertyChanged(nameof(CaptionMain)); }
        }


        public ICommand ShowHomeViewCommand { get; }
        public ICommand ShowEmployeeViewCommand { get; }
        public ICommand ShowDetailViewCommand { get; }
        public ICommand ShowProfileViewCommand { get; }

        public AdminViewModel()
        {
            _userRepository = new UserRepository();
            ShowHomeViewCommand = new CommandViewModel(ExecuteShowHomeViewCommand);
            ShowEmployeeViewCommand = new CommandViewModel(ExecuteShowEmployeeViewCommand);
            ShowDetailViewCommand = new CommandViewModel(ExecuteShowDetailsViewCommand);
            ShowProfileViewCommand = new CommandViewModel(ExecuteShowProfileViewCommand);

            ExecuteShowHomeViewCommand(null);
        }

        private void ExecuteShowHomeViewCommand(object obj)
        {
            BaseViewModel = new HomeAdminViewModel();
            Caption = "Страница / Каталог";
            CaptionMain = "Каталог";
        }

        private void ExecuteShowEmployeeViewCommand(object obj)
        {
            BaseViewModel = new EmployeeViewModel();
            Caption = "Страница / Сотрудники";
            CaptionMain = "Сотрудники";
        }

        private void ExecuteShowDetailsViewCommand(object obj)
        {
            BaseViewModel = new DetailsViewModel();
            Caption = "Страница / Детали";
            CaptionMain = "Детали";
        }

        private void ExecuteShowProfileViewCommand(object obj)
        {
            BaseViewModel = new ProfileViewModel();
            (BaseViewModel as ProfileViewModel).CurrentUser = CurrentUser;
            Caption = "Страница / Профиль";
            CaptionMain = "Профиль";
        }
    }
}
